package com.cloud.drore.eboss.supplier.controller;

import com.cloud.drore.eboos.common.base.PagePo;
import com.cloud.drore.eboos.common.base.ResultMessage;
import com.cloud.drore.eboss.supplier.entity.Supplier;
import com.cloud.drore.eboss.supplier.service.impl.SupplierServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.sql.ResultSet;

/**
 * 浙江卓锐科技股份有限公司 版权所有  Copyright 2018<br>
 *
 * @Description: <br>
 * @Project: eboos <br>
 * @CreateDate: Created in 2018/1/8 13:44 <br>
 * @Author: <a href="575842778@qq.com">郑永涛</a>
 */
@RestController
@RequestMapping("/Supplier")
@Api(value = "/供应商接口", description = "供应商接口-郑永涛")
public class SupplierController {

    @Resource
    SupplierServiceImpl supplierService;

    /**
     * @ClassName: SupplierController
     * @param resultSet
     * @Return: java.sql.ResultSet
     * @Decription:
     * @CreateDate: Created in 2018/1/8 14:37
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    public ResultSet get(ResultSet resultSet){
        return null;
    }


    @ApiOperation(value = "保存信息")
    @PostMapping(value = "/save")
    public ResultMessage<Supplier> save(@RequestBody @Validated({Supplier.SAVE.class})  Supplier supplier){
        return new ResultMessage(supplierService.insert(supplier));
    }

    @ApiOperation(value = "更新信息")
    @PutMapping(value = "/update")
    public ResultMessage<Supplier> update(@RequestBody @Valid Supplier supplier){
        return new ResultMessage(supplierService.updateByPrimaryKey(supplier));
    }

    @ApiOperation(value = "删除信息")
    @DeleteMapping(value = "/delete/{id}")
    public ResultMessage<Supplier> delete(@PathVariable("id") Long id){
        return new ResultMessage(supplierService.deleteByPrimaryKey(id));
    }

    @ApiOperation(value = "通过id获取信息")
    @GetMapping(value = "/{id}")
    public ResultMessage<Supplier> get(@PathVariable("id") Long id){

        return new ResultMessage(supplierService.selectByPrimaryKey(id));
    }

    @ApiOperation(value = "查询信息")
    @PostMapping(value = "find")
    public ResultMessage find(@RequestBody PagePo<Supplier> pagePo){
        Supplier supplier = pagePo.getFields();
        return supplierService.findByName(pagePo);
    }

}